﻿
#include "File.h"

#if defined( _WIN32 )
#include <direct.h>
#endif	// _WIN32

#if defined( __linux__ )
#include <unistd.h>
#endif	// linux

dn_namespace_beg
	

namespace
{
	void InitDataDir(FileSys* pFS)
	{
		pFS->DataDir[Data] = "";//"\\Resources";
		pFS->DataDir[Res] = "\\res";
		pFS->DataDir[EXD] = "\\exd";
		
		
	}
}

FileSys* FileSys::_inst = NULL;


FileSys& FileSys::Instance()
{
	if(_inst==0)
	{
		_inst = new FileSys;
	}

	return *_inst;
}

FileSys::FileSys()
{
	InitDataDir(this);
}

FileSys::~FileSys()
{

}


std::string FileSys::GetAppRootDir()
{
	char   Buffer[MAX_DIR_STR_SIZE]; 
	_getcwd(Buffer,   MAX_DIR_STR_SIZE);

	std::string Path(Buffer);
	return Path;
}


std::string FileSys::IntegrateFilePath(BaseDir eBDir,const std::string& RelativePath  )
{
	std::string RootPath = GetAppRootDir();

	std::string BasePath;
	if(eBDir>DataDir_Beg || eBDir<DataDir_End)
	{
		BasePath =  DataDir[Data]+DataDir[eBDir];
	}
	else if(eBDir>ResDir_Beg || eBDir<ResDir_End)
	{
		BasePath =  DataDir[Res]+DataDir[eBDir];
	}

	std::string FinalPath = RootPath+BasePath+"\\"+RelativePath;

	return FinalPath;
}
	

dn_namespace_end
